import request from './request'

/**
 * 获取首页的列表数据
 * import { getProlist } from '@/api'
 * 数据接口参考： http://localhost:3000/apidoc/#api-pro-GetApiPro
 * @param {Object} params 由limit和count组成的对象
 */
export function getProlist (params) {
  // limit和count的默认值 -- 依据接口文档设置
  const data = params || { limit: 10, count: 0 }
  return request({
    url: '/pro',
    method: 'get',
    params: data
  })
}
/**
 * 请求首页轮播图数据
 */
export function getBannerlist () {
  return request({
    url: '/banner',
    method: 'get'
  })
}

/**
 * 注册
 * @param {Object} params { tel: '', password: ''}
 */
export function register (params) {
  return request({
    url: '/users/register',
    method: 'post',
    data: params
  })
}
/**
 * 登录
 * @param {Object} params { tel: '', password: ''}
 */
export function login (params) {
  return request({
    url: '/users/login',
    method: 'post',
    data: params
  })
}
/**
 * 获取分类接口
 */
export function getCategory () {
  return request({
    url: '/category/getCategory',
    method: 'get'
  })
}
/**
 * 获取分类下品牌接口
 * @param {Object} params { type }
 */
export function getCategoryBrand (params) {
  return request({
    url: '/category/getCategoryBrand',
    method: 'get',
    params
  })
}

/**
 * 获取当前分类下当前品牌的产品数据
 * @param {Object} params { type, brand }
 */
export function getCategoryBrandList (params) {
  return request({
    url: '/category/getCategoryBrandList',
    method: 'get',
    params
  })
}
/**
 * 根据产品的id获取数据
 * @param {Object} params  { proid: '' }
 */
export function getDetailData (params) {
  return request({
    url: '/pro/detail',
    method: 'get',
    params
  })
}
/**
 * 加入购物车
 * @param {Object} params { userid: '', proid: '', num: 1}
 */
export function addCart (params) {
  return request({
    url: '/cart/add',
    method: 'post',
    data: params
  })
}

/**
 * 添加地址
 * @param {Object} params { userid, isDefault, name, tel, province, city, county, addressDetail }
 */
export function addAddress (params) {
  return request({
    url: '/address/add',
    method: 'post',
    data: params
  })
}

/**
 * 修改地址
 * @param {Object} params { addressid, userid, token, isDefault, name, tel, province, city, county, addressDetail }
 */
export function updataAddress (params) {
  return request({
    url: '/address/update',
    method: 'post',
    data: params
  })
}
/**
 * 删除地址
 * @param {Object} params { addressid, token }
 */
export function deleteAddress (params) {
  return request({
    url: '/address/delete',
    method: 'post',
    data: params
  })
}
/**
 * 获取地址列表
 * @param {Object} params { userid }
 */
export function getAddressData (params) {
  return request({
    url: '/address',
    method: 'get',
    params
  })
}
/**
 * addressid获取地址列表
 * @param {Object} params { addressid }
 */
export function getAddeditData (params) {
  return request({
    url: '/address/edit',
    method: 'get',
    params
  })
}
/**
 * 修改订单的收货人信息
 * @param {Object} params { orderid, addressid }
 */
export function updateOrderAddress (params) {
  return request({
    url: '/order/updateAddress',
    method: 'get',
    params
  })
}
/**
 * 删除订单
 *  * @param {Object} params { orderid }
 */
export function deleteOrder (params) {
  return request({
    url: 'order/deleteOrder',
    method: 'get',
    params
  })
}
/**
 * 查看购物车
 * @param {Object} params { userid: '' }
 */
export function getCartData (params) {
  return request({
    url: '/cart',
    methos: 'get',
    params
  })
}
/**
 * 更新购物车
 * @param {Object} params { cartid: '', num: 0 }
 */
export function updateCartData (params) {
  return request({
    url: '/cart/update',
    methos: 'get',
    params
  })
}

/**
 * 更新单选框
 * @param {Object} params { cartid: '', flag: 0 }
 */
export function getChecked (params) {
  return request({
    url: '/cart/checked',
    method: 'get',
    params
  })
}

/**
 * 更新全选框
 * @param {Object} params { userid: '', flag: 0 }
 */
export function getallchecked (params) {
  return request({
    url: '/cart/allchecked',
    method: 'get',
    params
  })
}
/**
 * 删除购物车
 * @param {Object} params { cartid: '' }
 */
export function deleteCartData (params) {
  return request({
    url: '/cart/delete',
    methos: 'get',
    params
  })
}
/**
 * 添加订单  ---  确认订单
 * @param {Object} params { userid: ''， orderlist: '[{},{}]' }
 */
export function addOrder (params) {
  return request({
    url: '/order/add',
    method: 'post',
    data: params
  })
}
/**
 * 根据关键字获取产品信息
 * @param {Object} params { value: ''}
 */
export function searchItem (params) {
  return request({
    url: '/search/search',
    method: 'get',
    params
  })
}
/**
 * 获取当前用户信息
 *  * @param {Object} params { userid, token }
 */
export function getuserinfo (params) {
  return request({
    url: 'users/getuserinfo',
    method: 'get',
    params
  })
}
/**
 * 修改用户信息
 *  * @param {Object} params { userid, token, nickname, email, sex}
 */
export function updateinfo (params) {
  return request({
    url: 'users/updateinfo',
    method: 'post',
    data: params
  })
}

/**
 * 上传头像
 *  * @param {Object} params { userid, token, avatar}
 */
export function updateAvatar (params) {
  return request({
    url: '/users/updateAvatar',
    method: 'post',
    data: params
  })
}
/**
 * 收藏的产品
 * @param {Object} params { collectionData, token }
 */
export function getCollection (params) {
  return request({
    url: '/users/getCollection',
    method: 'get',
    params
  })
}
/**
 * 查询订单
 * @param {Object} params { orderid: '' }
 */
export function getOrderData (params) {
  return request({
    url: '/order',
    method: 'get',
    params
  })
}
/**
 * 查询当前分类下所有产品数据
 * @param {Object} params { type: '' }
 */
export function getTypeProList (params) {
  return request({
    url: '/category/getTypeProList',
    method: 'get',
    params
  })
}
